<?php
include_once "../conn.php";
require('thumbnail_party.class.php');
?>

<script src="prototype.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
function findSub(){
new Ajax.Request('findstate.php', {
	method: 'get',
	parameters:{

						 id: $F('country')
						},
	onLoading: function() { $('sub').update('Loading...') },
	onSuccess: function(transport){
						 if(transport.responseText){
						 	$('sub').update(transport.responseText);
						}
					}
				});
}
//-->
</SCRIPT>
<?php

if (isset($_POST[s1])) {
	if (!empty($_FILES[images][name])) {
				$NewImageName = $_FILES[images][name];
				copy($_FILES[images][tmp_name], "re_images/".$NewImageName);
	} else {
				$NewImageName = 'no.jpg';
	}

			$thumb =& new thumbnail_party();
			$thumb->set_cache_path(NULL);
			$thumb->set_imagemagick_path(NULL);
			$thumb->set_source_file ('re_images/'.$NewImageName);
			$thumb->set_output_type ('jpg');
			//$thumb->set_background ('#ffffff');
			$thumb->intJPEGQuality = 85;
			$thumb->set_thumbnail_size (70, 40);
			$thumb->output('cache/images/'.$NewImageName);

	$q1 = "insert into job_employer_info set
		ename = \"$_POST[ename]\",
		epass = \"$_POST[epass]\",
		ContactName = '$_POST[ContactName]',
		position = '$_POST[position]',
		CompanyLogo = '$NewImageName',
		YearEstablished = '$_POST[YearEstablished]',
		website = '$_POST[web]',
		capital = '$_POST[capital]',
		employees = '$_POST[employees]',
		CompanyName = \"$_POST[CompanyName]\",
		CompanyCountry = \"$_POST[country]\",
		CompanyProfile = \"$_POST[CompanyProfile]\",
		CompanyState = \"$_POST[state]\",
		CompanyZip = \"$_POST[CompanyZip]\",
		CompanyCity = \"$_POST[CompanyCity]\",
		street = \"$_POST[street]\",
		CompanyAddress = \"$_POST[CompanyAddress]\",
		CompanyPhone = \"$_POST[CompanyPhone]\",
		CompanyPhone2 = \"$_POST[CompanyPhone2]\",
		fax = \"$_POST[fax]\",
		CompanyEmail = \"$_POST[CompanyEmail]\"";


		$r1 = mysql_query($q1);

		if(mysql_error())
		{
			$error = "<br><span class=TNA>Duplicate username: $_POST[ename]</span>";
			unset($_POST[ename]);
		}
		else
		{
			$to = $CompanyEmail;
			$subject = "Your account at $_SERVER[HTTP_HOST]";
			$message = "This is your account information at $_SERVER[HTTP_HOST]\n\n username: $_POST[ename]\n password: $_POST[epass]\n\n\n Keep this information in a secure place. \n\n Thanks for your registration. We believe you will find the staff you need at  http://$_SERVER[HTTP_HOST] ";
			$from = "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>";

			mail($to, $subject, $message, $from);

			$_SESSION[ename] = $_POST[ename];
			echo "<script>top.location = 'thanks.php'</script>";
			//header("location:thanks.php");
			exit();
		}

}


include_once "../main.php";
?>
<br>
<script>
function CheckEmployer() {

	if(document.f1.ContactName.value=="")
	{
		alert('Enter a contact name, please!');
		document.f1.ContactName.focus();
		return false;
	}

	if(document.f1.position.value=="")
	{
		alert('Select your position, please!');
		document.f1.position.focus();
		return false;
	}

	if(document.f1.CompanyName.value=="")
	{
		alert('Enter your company name, please!');
		document.f1.CompanyName.focus();
		return false;
	}

	if(document.f1.country.value=="")
	{
		alert('Select your company country, please!');
		document.f1.CompanyCountry.focus();
		return false;
	}

	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.f1.CompanyEmail.value))
	{
		alert("Invalid E-mail Address! Please re-enter.");
		document.f1.CompanyEmail.value="";
		document.f1.CompanyEmail.focus();
		return false;
	}

	if(document.f1.ename.value=="")
	{
		alert('Enter your login name, please!');
		document.f1.ename.focus();
		return false;
	}

	if(document.f1.epass.value=="")
	{
		alert('Enter your password, please!');
		document.f1.epass.focus();
		return false;
	}

	if(document.f1.cpass.value=="")
	{
		alert('Confirm your password, please!');
		document.f1.cpass.focus();
		return false;
	}

	if(document.f1.epass.value != "" && document.f1.cpass.value != "" && document.f1.epass.value != document.f1.cpass.value)
	{
		alert('Enter and confirm your password again!');
		document.f1.epass.value="";
		document.f1.cpass.value="";
		document.f1.epass.focus();
		return false;
	}

}
</script>

<form action=employer_registration.php method=post onsubmit="return CheckEmployer();" name=f1 enctype="multipart/form-data">
<table width=600 border="0" align=center cellpadding="3" cellspacing=0 class=BlackText>
<caption align=center class=HeaderClass>Employer Registration Form<?=$error?></caption>
<tr>
  <td colspan=2>&nbsp;</td>
</tr>
<tr>
	<td colspan=2 class="BlackLink row1"><strong>Company details</strong></td>
</tr>
<tr>
  <td align=left>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
	<td align=left>Contact name<font color=red>*</font></td>
	<td><input type=text name=ContactName value="<?=$_POST[ContactName]?>"></td>
</tr>
<tr>
	<td align=left>Position<font color=red>*</font></td>
	<td>
		<select name="position">
              <option value="Owner" <? if($_POST[position] == "Owner") { echo "selected"; } ?>>Owner</option>
              <option value="Director" <? if($_POST[position] == "Director") { echo "selected"; } ?>>Director</option>
              <option value="HR Director" <? if($_POST[position] == "HR Director") { echo "selected"; } ?>>HR Director</option>
              <option value="HR Manager" <? if($_POST[position] == "HR Manager") { echo "selected"; } ?>>HR Manager</option>
              <option value="HR Assistant" <? if($_POST[position] == "HR Assistant") { echo "selected"; } ?>>HR Assistant</option>
        </select>	</td>
</tr>
<tr>
<td align=left>
<label for="images">Company Logo:</label></td>
		<td><input type=file name="images" id="images"></td>
</tr>
<tr>
	<td align=left>Company name (legal)<font color=red>*</font></td>
	<td><input type=text name=CompanyName value="<?=$_POST[CompanyName]?>"></td>
</tr>
<tr>
	<td align=left valign="top">Company Profile</td>
	<td><textarea rows=6 cols=35 name=CompanyProfile  style="width:350px"></textarea></td>
</tr>
<tr>
	<td align=left>Year Established</td>
	<td><input type=text name=YearEstablished size=5 maxlength=4 value="<?=$_POST[YearEstablished]?>"></td>
</tr>
<tr>
	<td align=left>Website</td>
	<td><input type=text name=web size=20  value="<?=$_POST[web]?>"></td>
</tr>
<tr>
	<td align=left>Reg. capital</td>
	<td><input type=text name=capital value="<?=$_POST[capital]?>" size=10></td>
</tr>
<tr>
	<td align=left>No. employees</td>
	<td><input type=text name=employees size=10 maxlength=10 value="<?=$_POST[employees]?>"></td>
</tr>
<tr>
  <td align=left>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
	<td colspan=2 class="BlackLink row1"><strong>Company address</strong></td>
</tr>
<tr>
  <td align=left>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
	<td align=left>Address</td>
	<td><input type=text name=CompanyAddress value="<?=$_POST[CompanyAddress]?>"></td>
</tr>
<tr>
	<td align=left>Street</td>
	<td><input type=text name=street value="<?=$_POST[street]?>"></td>
</tr>
<tr>
	<td align=left>Town/city</td>
	<td><input type=text name=CompanyCity value="<?=$_POST[CompanyCity]?>"></td>
</tr>
<tr>
	<td align=left>State/Province:</td>
	<td>
		<div id="sub">
			<select name=state>
				<option value=" ">Select</option>
<?php
foreach ($state as $key => $value){
?>
		<option value="<?=$value?>"><?=$value?></option>
<?php
}
?>
			</select>
		</div></td>
</tr>
<tr>
	<td align=left>Country:<font color=red>*</font></td>
	<td><?=select_country($country, "country");?></td>
</tr>
<tr>
	<td align=left>Zip/Postal code</td>
	<td><input type=text name=CompanyZip value="<?=$_POST[CompanyZip]?>"></td>
</tr>
<tr>
	<td align=left>Telephone</td>
	<td><input type=text name=CompanyPhone value="<?=$_POST[CompanyPhone]?>"></td>
</tr>
<tr>
	<td align=left>Mobile number</td>
	<td><input type=text name=CompanyPhone2 value="<?=$_POST[CompanyPhone2]?>"></td>
</tr>
<tr>
	<td align=left>Fax number</td>
	<td><input type=text name=fax value="<?=$_POST[fax]?>"></td>
</tr>
<tr>
	<td align=left>E-mail<font color=red>*</font></td>
	<td><input type=text name=CompanyEmail size=34 value="<?=$_POST[CompanyEmail]?>"></td>
</tr>
<tr>
  <td align=left>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
	<td colspan=2 class="BlackLink row1"><strong>Login details</strong></td>
</tr>
<tr>
  <td align=left valign=middle>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
	<td align=left valign=middle>Choose a login name<font color=red>*</font></td>
	<td><input type=text name=ename maxlength=10 value="<?=$_POST[ename]?>"> max. 10 symbols</td>
</tr>
<tr>
	<td align=left>Choose a password<font color=red>*</font></td>
	<td><input type=password name=epass maxlength=10> max. 10 symbols</td>
</tr>
<tr>
	<td align=left>Confirm password<font color=red>*</font></td>
	<td><input type=password name=cpass maxlength=10></td>
</tr>
<tr>
	<td align=left>&nbsp;</td>
	<td align=right><input type="submit" name="s1" value="Register me" />&nbsp;
	<input type=reset name=reset value="Reset"></td>
</tr>
</table>

</form>

<?php include_once('../footer.php'); ?>